package com.bwie.create;

import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

@Service
public class CreateAsync {

    @Bean("asyncyqw")
    public Executor createqueue(){
        System.out.println("线程初始化");
        ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
        threadPoolTaskExecutor.setCorePoolSize(1); //设置线程数
        threadPoolTaskExecutor.setMaxPoolSize(3); //设置最大线程数
        threadPoolTaskExecutor.setQueueCapacity(0); //设置线程队列
        threadPoolTaskExecutor.setKeepAliveSeconds(1000); //设置线程等待时间
        //设置线程报错返回策略
        threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
        threadPoolTaskExecutor.setThreadNamePrefix("asdedd-"); //设置线程前缀名
        threadPoolTaskExecutor.initialize(); //设置线程初始化
        System.out.println("线程初始化完毕");
        return threadPoolTaskExecutor;
    }
}
